#ifndef _BOARD_DATA_PROC_H
#define _BOARD_DATA_PROC_H
#include <stdio.h>

//opcode from sub board
typedef enum
{
	SUB_ALARM = 0,
	SUB_TEMPORATURE = 1,
	SUB_ECHO = 2,
	SUB_MOVE = 3,
	SUB_CAPACITY = 4,
    SUB_ACK = 5,
	SUB_INTERRUPT = 6,
	SUB_NOTIFY = 7,
    SUB_PARAMETER = 8,
	SUB_ROTATE = 9,
	SUB_BARCODE = 10,
	SUB_SIGNAL = 11,
}en_op_code;


#define SUBBOARD_BASE 120

typedef enum
{
	NOT_EXIST_BOARD = 0,
	ELE_CTL_BOARD = 1,
	IO_EXPAND_BOARD = 2,
	CAP_DETECT_BOARD = 3,
	PURIFICATION_BOARD = 4,
    THERMAL_SEAL_BOARD = 5,
	QPCR_CTRL_BOARD = 6,
	SYSTEM_CTRL_BOARD = 7,
    QPCR_CTRL_BOARD_1 = 8,
	AIR_PRESSURE_BOARD = 9,
	SCANCODE_BOARD = 10,
    MAX_BOARD_NUM

}BOARD_ID;


#define MAX_LIQUID_CTRL_NUM 6
#define MAX_LIQUID_CTRL_NUM_Q 6

typedef void (*func_board_data_proc)(unsigned char lenIn, unsigned char * data,void*dataOut);

extern func_board_data_proc const func_data_proc[MAX_BOARD_NUM];

void ele_ctl_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
void io_expand_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
void cap_detect_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
void purification_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
void thermal_seal_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
void qpcr_ctrl_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
void system_ctrl_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
void qpcr1_ctrl_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
void air_pressure_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
void scancode_data_proc(unsigned char lenIn, unsigned char * data,void*dataOut);
//for test---
extern int fd_data_temp;
extern char strToWrite[1024];
extern int lenInStr;
extern int numData;

//opcode from centre to sub board
typedef enum {
	CENTRE_START,
	CENTRE_CONFIG,
	CENTRE_STOP,
	CENTRE_READ,
	CENTRE_ECHO,
	CENTRE_RETBACK,
	MAX_OP_FROM_CENTRE,
}en_opcode;

typedef enum
{
	CENTRE_QPCR_QLIGHT = 5,//light for qpcr
	CENTRE_QPCR_ENLIGHT = 6,//light for enlight
}en_qpcr_opcode;



typedef enum
{
	CENTRE_MOVE,	
	CENTRE_SAMPLE_TEMPERATURE,
    CENTRE_SAMPLE_CAP,

}en_centre_type;

typedef enum {
	PID_KP,
	PID_KI,
	PID_KD,
	PID_TAR,
}en_pid_param;

typedef struct _pidConfig
{
	int pidChum;
	int pidOpcode;
	float kp;
	float ki;
	float kd;

	unsigned int target;
}pidConfig;

//
typedef enum {
	CAP_RECALIBRATE,
	CAP_INTERRUPT,
    CAP_SAMPLE,
	CAP_DELATA_ENV_TIP,
	CAP_DELATA_ENV_LIQUID,
    CAP_DELATA_ENV_SUCK,
	CAP_PROBE_LIQUID
}en_cap_param_type;

typedef enum {
	PURIFY_SHAKE,
	PURIFY_BULLDOZE,
	PURIFY_HEAT,
	PURIFY_DUTYCYCLE,
	PURIFY_ROTATE_SPEED_CNT,//used for start or stop report rotate speed and configure rotate speed
	PURIFY_TEMPERATURE,
}en_purify_param_type;

#define MAX_NUM_SHAKE 5
#define MAX_PID_NUM 5

extern unsigned char purify_board_msg_src_heat[MAX_PID_NUM];
extern unsigned char purify_board_msg_src_shake[MAX_NUM_SHAKE];

typedef enum {
	THERMAL_HEAT,
	THERMAL_TEMPERATURE,
}en_thermal_param_type;

typedef enum
{
    SEAL_CHAN_SEAL = 1,
	SEAL_CHAN_SPLIT_L,
	SEAL_CHAN_SPLIT_R,
}en_chan_seal;

typedef enum
{
    QPCR_KPR = 0,
	QPCR_KPF,
	QPCR_ITR,
	QPCR_ITF,
	QPCR_DTR,
	QPCR_DTF,
	QPCR_HIGHT,
    QPCR_LOWT,
	QPCR_LIDT,
	QPCR_PT,
	QPCR_NT,
	QPCR_AHT,
	QPCR_ALT,
	QPCR_CT,
	QPCR_HKT,
	QPCR_LKT,
	QPCR_HST,
	QPCR_LST,
	QPCR_PHOTO,
	QPCR_MAX_TYPE
}en_qpcr_partype;

typedef enum
{
	ELE_MOVE_FINISHED = 0,
	ELE_MOVE_ABORT = 1,
    ELE_RETBACK_FINISHED = 2,	
}en_ele_ctl_type;


typedef enum
{
	LIQUID_ACT_FINISHED,
	FLOATER_SIG,
	SCANCODE_DRAWER_LOCK,
}en_dj_act_result;


typedef enum {
	SYSCTL_LIQUID,
	SYSCTL_SAMPLE,
	SYSCTL_BUZZ,
    DRAWER_LOCK,
}en_djctl_param_type;

extern unsigned char io_board_msg_src_dj[];
extern unsigned char io_board_msg_src_drawer[];

typedef enum {
    SCANCODE_SCAN,
	SCANCODE_VALUE,
}en_scancode_param_type;

typedef struct _recvSubBoardGram 
{
	unsigned char boardId;
	unsigned char opCode;
	unsigned char chanNum;
    unsigned char paramType;
	union {
        int value_i;
		float value_f;
	}un_paramData;
}recvSubBoardGram;

#define MAX_DATA_BUFF 1024

#define PURIFY_READ_TEMP_BASE 0 
#define PURIFY_SHAKE_BASE 16
#define PURIFY_HEAT_BASE 32

void encap_pid_gram(pidConfig * configIn,int sidIn,int * numOut, void * dataOut );
void encap_thermal_gram(unsigned char op_code, unsigned char chanNum, 
unsigned char paramTypeIn, void * paramData,void * dataOut);
void encap_thermal_gram_en(unsigned char op_code, unsigned char chanNum, 
unsigned char paramTypeIn, void * paramData,void * dataOut);
void encap_temperature_gram(unsigned char op_code,unsigned char chanNum, void * dataOut );
void encap_qpcr_gram(int qpcrId, unsigned char op_code, void * ctlData, void * dataOut);

void encap_qpcr_gram_en(int qpcrId, unsigned char op_code, void * ctlData, void * dataOut);

void encap_qpcr_gram_and_send(int qpcrId, unsigned char op_code, void * ctlData,void * pstCanIn);

void encap_cap_gram(unsigned char op_code, unsigned short chanNum, 
unsigned char paramTypeIn, void * paramData,void * dataOut);

void encap_purify_gram(unsigned char op_code, unsigned short chanNum, 
unsigned char paramTypeIn, void * paramData,void * dataOut);

void encap_io_expand_gram(unsigned char op_code, unsigned short chanNum, 
unsigned char paramTypeIn, void * paramData,void * dataOut);

void encap_djctl_gram(unsigned char op_code, unsigned short chanNum, 
unsigned char paramTypeIn, void * paramData,void * dataOut);

void encap_air_pressure_gram(unsigned char op_code, unsigned short chanNum, 
unsigned char paramTypeIn, void * paramData,void * dataOut);

void encap_scancode_gram(unsigned char op_code, unsigned short chanNum, 
unsigned char paramTypeIn, void * paramData,void * dataOut);


typedef struct _dataFile
{
    FILE * m_fd;
	char * m_buff;
	int m_currBufSize;
	int dataNum;
}dataFile;

class CDataFile
{
private:
	dataFile * dataFiles;
	int maxChanNum;
	int * fileChanNum;
public:
    CDataFile(const char* fileName,const int buffSize);
	CDataFile(const char* fileName,int boardId, const int chanMask,const int buffSize=MAX_DATA_BUFF);
	virtual ~CDataFile();
    int addToDataBuff(const char* data,int len);
    //int writeToFile(void);

	int addToDataBuff(const char* data,int len, int chan);
	int writeToFile(int chan = 0);

	int isValid(int fileIndex = 0);

	int getFileIndex(int chan);
	
};

extern CDataFile * g_fileCapData;

void *threadDataSample(void * param);

void startSampleThread(void);

void sendQpcrSheme(int qpcrIdIn, void * pstCan);

typedef struct _temperature_report_ctl
{
    int count_tar;
	int count_curr;
	int needReport;	
}temperature_report_ctl;

typedef enum
{
	CHAN_TEMP_SEAL,
	CHAN_TEMP_SEAL_BASE = CHAN_TEMP_SEAL,
	CHAN_TEMP_SHAKE1,
	CHAN_TEMP_SHAKE_BASE = CHAN_TEMP_SHAKE1,
	CHAN_TEMP_SHAKE2,
	CHAN_TEMP_SHAKE3,
	CHAN_TEMP_SHAKE4,
	CHAN_TEMP_SHAKE5,
	CHAN_TEMP_Q1_1,//for target temp
	CHAN_TEMP_Q1_BASE = CHAN_TEMP_Q1_1,
	CHAN_TEMP_Q1_2,//for lid temp
	CHAN_TEMP_Q1_3,//for chan temp
	CHAN_TEMP_Q1_4,
	CHAN_TEMP_Q1_5,
	CHAN_TEMP_Q1_6,
	CHAN_TEMP_Q1_7,
	CHAN_TEMP_Q2_1,
	CHAN_TEMP_Q2_BASE = CHAN_TEMP_Q2_1,
	CHAN_TEMP_Q2_2,
	CHAN_TEMP_Q2_3,
	CHAN_TEMP_Q2_4,
	CHAN_TEMP_Q2_5,
	CHAN_TEMP_Q2_6,
	CHAN_TEMP_Q2_7,
	CHAN_TEMP_Q3_1,
	CHAN_TEMP_Q3_BASE = CHAN_TEMP_Q3_1,	
	CHAN_TEMP_Q3_2,
	CHAN_TEMP_Q3_3,
	CHAN_TEMP_Q3_4,
	CHAN_TEMP_Q3_5,
	CHAN_TEMP_Q3_6,
	CHAN_TEMP_Q3_7,
	CHAN_TEMP_Q4_1,
	CHAN_TEMP_Q4_BASE = CHAN_TEMP_Q4_1,		
	CHAN_TEMP_Q4_2,
	CHAN_TEMP_Q4_3,
	CHAN_TEMP_Q4_4,
	CHAN_TEMP_Q4_5,
	CHAN_TEMP_Q4_6,
	CHAN_TEMP_Q4_7,	
	MAX_CHAN_TEMP_NUM
}en_temperature_chan;

#define MAX_CHAN_ONE_QPCR 7

extern temperature_report_ctl  tempReportCtlArr[MAX_CHAN_TEMP_NUM];

void initTempReportCtl(void);

int checkAndReportTemp(int boardId, int chanNumIn, float temperatureIn);

void setTempReportCtl(int chanTempBase, int chanNumIn, int interv_ms);

void setQpcrGrpReport(int qpcrId, int interv_ms);

typedef enum 
{
   LIGHT_QPCR_SOURCE,
   LIGHT_QPCR_LIGHTING
}en_qpcr_light;

#endif